package com.midian.service.organization.impl;

import java.io.Serializable;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.midian.common.dao.BaseDaoTemplet;
import com.midian.common.dao.OrderHelper;
import com.midian.common.dao.SearchHelper;
import com.midian.common.dao.SearchHelper.Type;
import com.midian.common.exception.BizException;
import com.midian.common.pager.Pager;
import com.midian.common.system.SysStatic;
import com.midian.model.organization.OrganizationType;
import com.midian.service.common.BaseService;
import com.midian.service.organization.IOrganizationTypeService;

/**
 * 机构类型业务实现类
 * @author Mengfh
 *
 */
@Service("organizationTypeService")
public class OrganizationTypeServiceImpl extends BaseService implements IOrganizationTypeService {
	/**机构类型DAO*/
	private BaseDaoTemplet<OrganizationType> organizationTypeDAO;
	
	@Resource(name = "organizationTypeDAO")
	public void setOrganizationTypeDAO(BaseDaoTemplet<OrganizationType> organizationTypeDAO) {
		this.organizationTypeDAO = organizationTypeDAO;
	}

	@Override
	public OrganizationType add(OrganizationType target) throws BizException {
		this.organizationTypeDAO.add(target);
		return target;
	}

	@Override
	public void update(OrganizationType target) throws BizException {
		this.organizationTypeDAO.updateByConvertHql(target);
	}

	@Override
	public void delete(Serializable id) throws BizException {
		this.organizationTypeDAO.delete(id);
	}

	@Override
	public void delete(Serializable[] ids) throws BizException {
		this.organizationTypeDAO.delete(ids);
	}

	@Override
	public OrganizationType get(Serializable id) throws BizException {
		return this.organizationTypeDAO.get(id);
	}

	@Override
	public List<OrganizationType> showList(OrganizationType target, Pager pager, List<OrderHelper> helper) throws BizException {
		return this.organizationTypeDAO.find(target, getSearchHelper(), helper, pager);
	}

	@Override
	public void opDelFlag(Serializable[] ids, Integer status) throws BizException {
		this.organizationTypeDAO.opDelFlag(ids, status);
	}

	@Override
	protected List<SearchHelper> getSearchHelper() {
		String[] attrs = {};
		Type[] types = {};
		return SearchHelper.getSearchList(attrs, types);
	}

	@Override
	public List<OrganizationType> geOrganizationTypes() throws BizException {
		String hql = "from OrganizationType t where t.delFlag = ?";
		return  this.organizationTypeDAO.find(hql, new Object[]{SysStatic.NORMALDELFLAG});
		
		
	}
}
